"""模拟测试路由"""
from fastapi import APIRouter, HTTPException, Body
from typing import Dict, Any, Optional
from app.services.mock_exam_service import mock_exam_service

router = APIRouter()


@router.post("/mock-exam/create")
async def create_mock_exam(
    user_id: str = Body(...),
    exam_type: str = Body("quick")
):
    """创建模拟测试"""
    if exam_type not in ["quick", "standard", "full"]:
        raise HTTPException(
            status_code=400,
            detail="测试类型必须是 quick、standard 或 full"
        )
    
    exam = await mock_exam_service.create_mock_exam(user_id, exam_type)
    return exam


@router.get("/mock-exam/{exam_id}")
async def get_exam_info(exam_id: str):
    """获取测试信息"""
    # 实际应该从数据库或Redis获取
    return {
        "exam_id": exam_id,
        "status": "created",
        "message": "请使用创建接口获取完整信息"
    }


@router.post("/mock-exam/{exam_id}/submit")
async def submit_mock_exam(
    exam_id: str,
    user_id: str = Body(...),
    answers: Dict[str, str] = Body(...),
    time_spent: int = Body(...)
):
    """提交模拟测试"""
    result = await mock_exam_service.submit_exam(
        exam_id, user_id, answers, time_spent
    )
    
    # 标记用户完成测试
    from app.services.user_onboarding_service import user_onboarding_service
    user_onboarding_service.mark_test_completed(user_id, result)
    
    return result


@router.get("/mock-exam/{exam_id}/question/{question_index}")
async def get_exam_question(
    exam_id: str,
    question_index: int
):
    """获取测试中的题目（按索引）"""
    # 实际应该从exam中获取question_ids，然后返回对应题目
    # 这里简化处理
    return {
        "exam_id": exam_id,
        "question_index": question_index,
        "message": "请使用创建接口获取完整题目列表"
    }
